package com.credentials;

import java.util.HashMap;

import com.login.LoginFunctions;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ChangeCredentials extends ActionSupport{
	private String user,pass;
	HashMap dataMap = new HashMap();
	
	public HashMap getDataMap() {
		return dataMap;
	}

	public void setDataMap(HashMap dataMap) {
		this.dataMap = dataMap;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		dataMap.put("username", user);
		ActionContext.getContext().getSession().put("datamap", dataMap);
		
		return "success";
	}
	
	
	@Override
	public void validate() {
		System.out.println("In change credential page validation "+user);
		LoginFunctions loginFunctions = new LoginFunctions();
		String role = loginFunctions.whatIsRole(user, pass);
		if (role.equals("")) {
			addActionError("user name or password is wrong");
			System.out.println("In change credential page validation invalid id");
		} 
		}
}
